﻿using AnnotateMe.Logic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;

namespace AnnotateMe.Test
{
    /// <summary>
    ///This is a test class for CaretDelimitedQueryParserTest and is intended
    ///to contain all CaretDelimitedQueryParserTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CaretDelimitedQueryParserTest
    {
        [TestMethod()]
        public void EmptyInputTest()
        {
            CaretDelimitedQueryParser target = new CaretDelimitedQueryParser();
            string query = string.Empty;
            IEnumerable<Tuple<string, string>> expected = Enumerable.Empty<Tuple<string, string>>();
            IEnumerable<Tuple<string, string>> actual;
            actual = target.Parse(query);
            CollectionAssert.AreEquivalent(expected.ToList(), actual.ToList());
        }

        [TestMethod()]
        public void SimpleInputTest()
        {
            CaretDelimitedQueryParser target = new CaretDelimitedQueryParser();
            string query = "Dummy string";
            IEnumerable<Tuple<string, string>> expected = new[] { new Tuple<string, string>(query, string.Empty) };
            IEnumerable<Tuple<string, string>> actual;
            actual = target.Parse(query);
            CollectionAssert.AreEquivalent(expected.ToList(), actual.ToList());
        }

        [TestMethod()]
        public void OnlyOneLabelInputTest()
        {
            CaretDelimitedQueryParser target = new CaretDelimitedQueryParser();
            string query = "(label)^(annotation)";
            IEnumerable<Tuple<string, string>> expected = new[] { new Tuple<string, string>("label", "annotation") };
            IEnumerable<Tuple<string, string>> actual;
            actual = target.Parse(query);
            CollectionAssert.AreEquivalent(expected.ToList(), actual.ToList());
        }

        [TestMethod()]
        public void SimpleEscapingInputTest()
        {
            CaretDelimitedQueryParser target = new CaretDelimitedQueryParser();
            string query = @"(label\)\^\(escape\\)";
            IEnumerable<Tuple<string, string>> expected = new[] { new Tuple<string, string>("(label)^(escape\\)", string.Empty) };
            IEnumerable<Tuple<string, string>> actual;
            actual = target.Parse(query);
            CollectionAssert.AreEquivalent(expected.ToList(), actual.ToList());
        }

        [TestMethod()]
        public void RecursiveLabelAndEscapingInputTest()
        {
            CaretDelimitedQueryParser target = new CaretDelimitedQueryParser();
            string query = @"((label)^(annotation))\^(annotation)";
            IEnumerable<Tuple<string, string>> expected = new[] { new Tuple<string, string>("(", string.Empty), new Tuple<string, string>("label", "annotation"), new Tuple<string, string>(")^(annotation)", string.Empty) };
            IEnumerable<Tuple<string, string>> actual;
            actual = target.Parse(query);
            CollectionAssert.AreEquivalent(expected.ToList(), actual.ToList());
        }
    }
}
